import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_share/flutter_share.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _WebViewPageState();
  }
}

class _WebViewPageState extends State<WebViewPage> {
  bool showLoading = false;

  @override
  Widget build(BuildContext context) {
    var child = <Widget>[
      WebView(
        initialUrl: 'http://edu.iseoo.com.cn:21000/staticresources/guide.html',
        javascriptMode: JavascriptMode.unrestricted,
        onPageStarted: (url) => {
          setState(() {
            showLoading = true;
          })
        },
        onPageFinished: (url) => setState(() {
          showLoading = false;
        }),
      ),
    ];
    if (showLoading) {
      child.add(LinearProgressIndicator(
          // valueColor: AlwaysStoppedAnimation(Colors.red),
          // backgroundColor: Colors.white,
          ));
    }
    return Scaffold(
        appBar: AppBar(
          title: Text('获取TFS Token教程'),
        ),
        body: Material(
            child: Stack(
          children: child,
        )) // This trailing comma makes auto-formatting nicer for build methods.
        );
  }

  @override
  void initState() {
    super.initState();
    // Enable hybrid composition.
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }
}
